package net.istore.market.web;

import net.istore.market.domain.Order;
import net.istore.market.domain.User;
import net.istore.market.service.user.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import java.util.Map;

/**
 * Created by Ivan_Zhuravel on 1/14/15.
 */
@Controller
public class RegistrationUserController {

    @Autowired
    private UserService userService;

    @RequestMapping("/registration")
    public String listContacts(Map<String, Object> map) {

        map.put("user", new User());

        return "registration";
    }

    @RequestMapping(value = "/registerNewUser", method = RequestMethod.POST)
    public String addContact(@ModelAttribute("user") User user,
                             BindingResult result) {

        userService.addUser(user);

        return "redirect:/registration";
    }
}
